Skip to content

Ignore v3 metadata members declaring must_understand: false - #94

Open
konstibob wants to merge 1 commit into
zarr-developers:mainfrom
konstibob:fix/must-understand-extra-fields
Open

Ignore v3 metadata members declaring must_understand: false#94
konstibob wants to merge 1 commit into
zarr-developers:mainfrom
konstibob:fix/must-understand-extra-fields

Conversation

@konstibob

Copy link
Copy Markdown
Contributor

A Zarr v3 writer may add members to a metadata document that a reader does not know about. When such a member is a JSON object carrying "must_understand": false, the specification requires a reader to ignore it; any other unknown member has to be rejected, because it may change how the array is to be interpreted.

Reading a zarr.json written by a newer implementation therefore failed with an UnrecognizedPropertyException on a member that was explicitly marked as safe to skip.

must_understand deliberately does not apply to codec, chunk grid or chunk key encoding names: a codec cannot be skipped and still leave the chunk bytes decodable, so an unknown name there still fails.

Verified against zarr-python 3.1.6 in both directions: a document it writes with an extra field now opens, and a document zarr-java rewrites is read back by zarr-python with the field intact in its own extra_fields.

A Zarr v3 writer may add members to a metadata document that a reader does
not know about. When such a member is a JSON object carrying
"must_understand": false, the specification requires a reader to ignore it;
any other unknown member has to be rejected, because it may change how the
array is to be interpreted.

zarr-java rejected every unknown member instead, because the ObjectMapper in
v3.Node was built with Jackson's default FAIL_ON_UNKNOWN_PROPERTIES. Reading
a zarr.json written by a newer implementation therefore failed with an
UnrecognizedPropertyException on a member that was explicitly marked as safe
to skip.

Unknown members are now collected through a @JsonAnySetter creator parameter
and validated in ExtraFields, which mirrors zarr-python 3.1.6
(zarr/core/metadata/v3.py):

  - a JSON object with "must_understand": false is ignored,
  - anything else is rejected with a ZarrException,
  - an extra field colliding with a member the document defines itself is
    rejected.

Ignored members are kept on the metadata and written back out by a
@JsonAnyGetter, so that another implementation's extension survives a
metadata rewrite. ArrayMetadataBuilder.fromArrayMetadata and
Group.setAttributes carry them over, which covers resize, setAttributes and
updateAttributes.

must_understand deliberately does not apply to codec, chunk grid or chunk key
encoding names: a codec cannot be skipped and still leave the chunk bytes
decodable, so an unknown name there still fails.

Verified against zarr-python 3.1.6 in both directions: a document it writes
with an extra field now opens, and a document zarr-java rewrites is read back
by zarr-python with the field intact in its own extra_fields.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant